/**hofit**/
package Controler;
import java.util.ArrayList;

import Client.*;
import DAL.SysUser_DAL;


public class Log_in_panel_controler  {
	/**
	 * 
	 * @param id  - id of the user
	 * @param ip  - ip of the server
	 * @param port - port that connect with the server
	 * @param password - passwors of the user
	 * @return true \ false
	 * the function check if the id and the password correct
	 * true: if the connection done ( id and password correct)
	 * else return false.
	 */
	public boolean checkconnection(String id,String ip, String port, String password)
	{
		if(BusinessImplements.GetInstance().getServerProxy()==null){
		ServerProxy s=new ServerProxy(ip, port);
		BusinessImplements.GetInstance().setServerProxy(s);
		}
		return BusinessImplements.GetInstance().getServerProxy().checkconnection(id, password);
	}
	public boolean createServerProxyForGuest(String ip, String port)
	{
		if(BusinessImplements.GetInstance().getServerProxy()==null){
		ServerProxy s=new ServerProxy(ip, port);
		BusinessImplements.GetInstance().setServerProxy(s);
		}
		if (BusinessImplements.GetInstance().getServerProxy()!=null)
			return true;
		else
			return false;
	}
/**
 * 
 * @param id - id of the user
 * @return the details of the user
 * the function send the id of the user and creates object with the user details
 */
	public SysUser_DAL getUserById(String id) {
		ArrayList<String> userDetailsStr=new ArrayList<String>();
		userDetailsStr=BusinessImplements.GetInstance().getServerProxy().getUserdetails(id);
		SysUser_DAL userLogin=new SysUser_DAL(userDetailsStr);
		return userLogin;
		
	}
	
	/**
	 * 
	 * @param id - id of the user that connect to the system
	 * @return true /false
	 * the method set flag that represent that the user connect
	 * and return true or false
	 */

	public ArrayList<String> update_useronline(String id) {
		
		ArrayList<String> userOn=new ArrayList<String>();
		userOn=BusinessImplements.GetInstance().getServerProxy().update_useronline(id,"1");
		return userOn;
	}
	
	/**
	 * 
	 * @param id - id of the user that connect to the system
	 * @return true /false
	 * the method turn off/ flag that represent that the user connect
	 * and return true or false
	 */
	public ArrayList<String> update_useroffline(String id) {
		
		ArrayList<String> userOn=new ArrayList<String>();
		userOn=BusinessImplements.GetInstance().getServerProxy().update_useronline(id,"0");
		return userOn;
	}
	
	/**
	 * 
	 * @param id - if of the user 
	 * @return true \ false
	 * check if the user already connect to the system 
	 * and return true or false
	 */

	public ArrayList<String> checkonline(String id) {
		ArrayList<String> userOn=new ArrayList<String>();
		userOn=BusinessImplements.GetInstance().getServerProxy().checkonline(id);
		return userOn;
	}
	
}

